package com.mephi.oshs.model.entry;

import com.mephi.oshs.model.Value;
import com.mephi.oshs.model.style.IStyle;

import java.util.Map;
import java.util.Observable;

/**
 * Элемент дерева ОШС.
 */
public class Entry extends Observable implements IEntry {

    private String shortName = "";
    private IStyle style = null;
    private Map<String, Value> attributes = null;

    public Entry(final String shortName) {
        this(shortName, null, null);
    }

    public Entry(final String shortName, final IStyle style, final Map<String, Value> attributes) {
        this.setShortName(shortName);
        this.setStyle(style);
        this.setAttributes(attributes);
    }

    /* E.N.T.R.Y */

    /**
     * {@inheritDoc}
     */
    @Override
    public Map<String, Value> getAttributes() {
        return this.attributes;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setAttributes(final Map<String, Value> attributes) {
        this.attributes = attributes;
        this.setChanged();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public IStyle getStyle() {
        return this.style;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setStyle(final IStyle style) {
        this.style = style;
        this.setChanged();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String getShortName() {
        return shortName;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void setShortName(final String shortName) {
        if (shortName != null && !this.shortName.equals(shortName)) {
            this.shortName = shortName;
            this.setChanged();
        }
    }

    /* O.B.J.E.C.T. */

    @Override
    public String toString() {
        return this.getShortName();
    }
}
